package com.xueyi.starter.file.controller;

import com.xueyi.core.base.BaseResponse;
import com.xueyi.starter.file.config.FileMinioSystemAutoProperties;
import com.xueyi.starter.file.config.MinioAutoConfiguration;
import com.xueyi.starter.file.utils.MinioUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 描述 基础的Minio的Control
 *
 * @author 俞烨
 * @date 2024-03-09 21
 */
@RestController
@RequestMapping("/common/minio")
@AllArgsConstructor
public class DefaultMinioController {


    private final MinioUtil minioUtil;

    @Resource
    private MinioAutoConfiguration minioAutoConfiguration;
    /**
     * minio的公共上传路径
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("/upload-file")
    public BaseResponse<?> uploadFile(MultipartFile file) throws Exception {
        String minioFile = minioUtil.uploadFile(file, minioAutoConfiguration.getFileMinioSystemAutoProperties().getDefaultBucketName());
        return BaseResponse.success(minioUtil.parseUrl(minioFile));
    }
}
